<?

//Created by Huynh.
//Last modified by Huynh
//On Feb 28th, 2012

//This is the class of card.
class Card
{
	//value = 1(A), 2, ..., 10, 11, 12, 13(K)
	private $value = 1; //Default value is 1.
	
	//suits: heart (4), diamond(3),... spade(1), 
	private $suit = 1; //Default value is 1.
	
	//get the value of the card.
	public function getValue()
	{
		return $this->value;
	}
	
	//Get the name of the suit.
	public function getSuit()
	{
		return $this->suit;
	}
	
	//Set the value of the card.
	public function setValue($v)
	{
		if ($v <= 0 || $v > 13)
		{
			die("Invalid value\n");
		}else
		{
			$this->value = $v;
		}
	}
	
	//set the value of hte suit.
	public function setSuit($s)
	{
		if ($s > 4 || $s < 1)
		{
			die("Invalid suit.\n");
		}else
		{
			$this->suit = $s;
		}
	}	
	
	//Construct the card.
	//The two parameters here are the value and the suit of the card.
	function __construct($v = 1, $s = 1)
	{
	
		$this->setValue($v);
		$this->setSuit($s);
	}
	
	//Return 0 if the two cards are the same, -1 if this card is
	//smaller than the other card and return 1 otherwise
	function compareTo($other)
	{	
		if ($this->value < $other->value)
		{
			return -1;
		}else if ($this->value > $other->value)
		{
			return 1;
		}else if ($this->suit > $other->suit)
		{
			return 1;
		}else if ($this->suit < $other->suit)
		{
			return -1;
		}else
		{
			return 0;
		}	
	}
}//End class Card.

//Compare two cards.
//This function can be used to sort an array of cards.
//(Using usort())
function cardCompare($card1, $card2)
{
	return $card1->compareTo($card2);
}//End function compare.
?>